import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "home",
    component: Home,
    meta: {
      active: 0,
    },
  },
  {
    path: "/theme",
    name: "theme",

    component: () =>
      import(/* webpackChunkName: "theme" */ "../views/Theme.vue"),
    meta: {
      active: 1,
    },
  },
  {
    path: "/categroy",
    name: "categroy",

    component: () =>
      import(/* webpackChunkName: "categroy" */ "../views/Categroy.vue"),
    meta: {
      active: 2,
    },
  },
  {
    path: "/cart",
    name: "cart",

    component: () => import(/* webpackChunkName: "cart" */ "../views/Cart.vue"),
    meta: {
      active: 3,
    },
    beforeEnter(to, from, next) {
      if (!localStorage.getItem("token")) {
        // console.log(Vue.prototype);
        Vue.prototype.$notify({
          type: "warning",
          message: "请先登录",
        });
        return;
      }
      next();
    },
  },

  {
    path: "/user",
    name: "user",

    component: () => import(/* webpackChunkName: "user" */ "../views/User.vue"),
    meta: {
      active: 4,
    },
  },
  {
    path: "/popup",
    name: "popup",

    component: () =>
      import(/* webpackChunkName: "popup" */ "../views/Popup.vue"),
  },
  {
    path: "/productDetail",
    name: "productDetail",

    component: () =>
      import(
        /* webpackChunkName: "productDetail" */ "../views/ProductDetail.vue"
      ),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
